import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { useState } from "react";

const Provider = ({children, queryClient: queryClientProp}:{children:React.ReactNode, queryClient?: QueryClient}) => {
  const [queryClient] = useState(() => queryClientProp || new QueryClient({
    defaultOptions: {
      queries: {
        staleTime: 1000 * 60 * 5, // 5分钟的缓存时间
        gcTime: 1000 * 60 * 10, // 10分钟的垃圾回收时间
        retry: 1, // 失败重试次数
        refetchOnWindowFocus: false, // 窗口获得焦点时不自动重新获取数据
      },
    },
  }));
  return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
}

export default Provider;